package com.longxi.tianjintianbao.ui.adapter.multitype.energy_read;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectMeterListener;
import com.longxi.tianjintianbao.model.meter.Meter;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class EnergyMeterViewBinder extends ItemViewBinder<Meter, EnergyMeterViewBinder.ViewHolder> {

    private boolean isWrite;
    SelectMeterListener listener;

    public EnergyMeterViewBinder(SelectMeterListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_meter, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Meter meter) {
        if(!"".equals(meter.getMeterno())){
            holder.mTvInstrumentNumber.setText("表号：" + meter.getMeterno());
        }
        if(!"".equals(meter.getMetername())){
            holder.mTvInstrumentNumber.setText("表名：" + meter.getMetername());
        }

        if("".equals(meter.getThisdegrees())){
            holder.mTvRecord.setText("上次抄表数：" + meter.getLastdegrees());
        }else{
            holder.mTvRecord.setHint("本次抄表数：" + meter.getThisdegrees());
            holder.mTvRecord.setText("");
        }

        if(!"".equals(meter.getMeteraddress())){
            holder.mTvAddress.setText("地址: " + meter.getMeteraddress());
        }
        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if("".equals(meter.getThisdegrees())){
                    listener.onSuccess(meter);
                }
            }
        });

    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvInstrumentNumber;
        TextView mTvRecord;
        TextView mTvAddress;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvInstrumentNumber = itemView.findViewById(R.id.tvInstrumentNumber);
            mTvRecord = itemView.findViewById(R.id.tvRecord);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
        }
    }
}
